package com.example.onedemotest.slice;

import com.example.onedemotest.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.ArrayList;

public class ListProvider extends BaseItemProvider{
    private ArrayList<String> datas;
    private Context mContext;

    public ListProvider(ArrayList<String> datas, Context context) {
        this.datas = datas;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int position, Component component, ComponentContainer componentContainer) {
        final Component cpt;
        if (component==null){
            cpt= LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_item_list_sample,null,false);
        }else {
            cpt=component;
        }
        Text sampleTxt = (Text) cpt.findComponentById(ResourceTable.Id_textItem);
        sampleTxt.setText(datas.get(position));
        return cpt;
    }
}